<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>如何访问每个查询字符串参数</title>
</head>

<body>
    <script type="text/javascript">
        // http://127.0.0.1:8080/
        // 0342432%#EFS.html?user=test&pwd=123
        // ?user=test&pwd=123
        /*
            var args = {
                user: 'test',
                pwd: '123'
            }
        */
        function getQueryString() {
            // 1. 取得去掉问号查询字符串
            // var qs = location.search; // ?user=test&pwd=123
            // qs = location.search.substring(1);
            var qs = location.search.length > 0 ? location.search.substring(1) : '';
            // 2. 取得每一项存放到数组中
            var items = qs.length ? qs.split('&') : [];
            console.log(items);
            var item = null, name = null, value = null, args = {};

            for (var i = 0; i < items.length; i++) {
                item = items[i].split('=');
                name = decodeURIComponent(item[0]);
                value = decodeURIComponent(item[1]);
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        }
        var args = getQueryString();
        console.log(args);
        console.log(args.name);
        console.log(args.pwd);
    </script>
</body>
</html>